<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title>校园二手物品交易平台</title>
    <link rel="stylesheet" href="/static/layui/css/layui.css">
    <script src="/static/layui/layui.js"></script>
    <script src="/static/JQuery/jquery-3.3.1.min.js"></script>
</head>

<body>

<div id="cover" style="background-image: url('/static/img/chuangxinbeijing.jpg');background-size:100%;">

    <div class="layui-main">

        <div class="layui-form-item">
            <br><br><br>
            <font size="16px" color="#7fffd4" style="font-family: 华文行楷">校园二手物品交易平台</font>
            <fieldset class="layui-elem-field layui-field-title" >
                <legend> </legend>
            </fieldset>

        </div>
        <br><br>
        <div class="layui-form-item">
            <form class="layui-form layui-col-md4 layui-col-md-offset4" lay-filter="registerForm">
                <input type="hidden" name="fkroleid" value="2" >
                <label style="background-color: red"></label>
                <fieldset class="layui-elem-field layui-field-title" >
                    <legend style="color: #000000;font-family: 楷体">欢迎注册</legend>
                </fieldset>
                <div class="layui-form-item">
                    <input name="username" type="text" placeholder="Username" class="layui-input">
                </div>
                <div class="layui-form-item">
                    <input name="password" type="password" placeholder="Password" class="layui-input">
                </div>
                <div class="layui-form-item">
                    <input name="realname" type="text" placeholder="RealName" class="layui-input">
                </div>
                <div class="layui-form-item">
                    <input name="sex" type="text" placeholder="Sex" class="layui-input">
                </div>
                <div class="layui-form-item">
                    <input name="age" type="text" placeholder="Age" class="layui-input">
                </div>
                <div class="layui-form-item">
                    <input name="phone" type="text" placeholder="Phone" class="layui-input">
                </div>
                <div class="layui-form-item">
                    <input name="email" type="text" placeholder="Email" class="layui-input">
                </div>
                <div class="layui-col-md-offset3">
                    <button type="button" class="layui-btn layui-btn-lg layui-btn-normal" lay-submit lay-filter="doRegister">注册</button>
                    <a href="/templates/login.html" class="layui-btn layui-btn-lg layui-btn-normal">返回登录</a>
                </div>
            </form>
        </div>

        <br><br><br>
    </div>

</div><!-- /.carousel -->

<script>
    //Demo
    layui.use(['element', 'layer','form'], function(){
        var form = layui.form;
        var element = layui.element;
        var layer = layui.layer;
        //监听提交
        form.on('submit(doRegister)', function(data){
            //layer.msg(JSON.stringify(data.field.username));
            $.ajax({
                url:"/system/register",
                type:"POST",
                data:JSON.stringify(data.field),
                async: false,
                contentType: "application/json;charset=utf-8",
                dataType : "json",
                success : function(result) {
                    if(result.code == 0){
                        parent.layer.msg(result.msg, {icon : 1});
                        window.location.replace("/templates/login.html");
                    }else {
                        parent.layer.msg("操作失败：" + result.msg, {icon : 5});
                    }
                },
                error:function(result){
                    parent.layer.msg("操作失败：" + result.msg, {icon : 5});
                }
            });
            return false;
        });

    });
</script>
</body>
</html>